<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/together.css"/>
		<style>
			.m_barw {background-color: rgba(247, 247, 247, 0)!important;}
			.ws_books_top{position:fixed; top:0; width:100%; height:30vh; z-index: 2;}
			.mr5 {
			    margin-right: 0.2em !important;
			}
			.mui-bar .mui-title{right:80px;}
		</style>
	</head>

	<body>
		 <header class="mui-bar  mui-bar-transparent m_barw" >
			 <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" id="htitle">详情</h1>
		    <a class="ws-icon ws_100  mui-icon-right-nav mui-pull-right mr5"  onclick="coll(2)">
		    	<img src="../images/sc1.png"/>
		    </a>
		</header>
		<div class="mui-content" >
			<div class="" id="contentid">
				
			</div>
			<div class="ws_details_popup" id="popdiv">
				
				<div class="mui-input-row">
				    <label>Input</label>
				    <input type="text" placeholder="普通输入框">
				</div>
				
			</div>
			
			<footer>
				<div  class="purchase">
					<span id="playt"> 立即购买 </span>  
					<span  onclick="gobook4()">预览</span>
				</div> 
			</footer>
			
		</div>
		<script	 src="../js/jquery.min.js"></script>
		<script src="../js/mui.js"></script>
		<script src="../js/req.js"></script>	
		<script src="../js/muishow.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var sid = 0,		//商品id
				addid = 24,		//地址id
				ist=0;			//
			window.onload = function(){
				mui.init();
				sid = getrequest().sid||0;
				console.log(sid)
				
				mui.plusReady(function () {
				   var self = plus.webview.currentWebview();
				   sid = self.sid;
				   ist = self.ist;
				})
				
				//监听购买
				$("#playt").click(function(){
					console.log("购买");
					mui.openWindow({
							    url: 'pay.html?sid='+sid, 
							    id:'pay',
							 });
					return;
					/*
					$(".ws_details_popup").stop(true,true).animate({top:"0%"},400,function(){
							$(".determine").removeClass("hide");
							$(".ws_details_close").removeClass("hide");
					});
					*/
				})
				
				bookdetails();
				
				if(ist){
					
					$(".ws_details_popup").stop(true,true).animate({top:"0%"},0,function(){
							$(".determine").removeClass("hide");
							$(".ws_details_close").removeClass("hide");
					});
				}
				
				
			}
			
			window.addEventListener('refresh',function(e){
				bookdetails();
			})
			
			
			
			function bookdetails(){
				let data = {
					url:"/api/Book/shop_book_info",
					data:{
						access_token : acctoken()||"",
						id:sid
					}
				}
				ajax(data,function(res){
					console.log("书本详情",res)
					g("htitle").innerHTML = res.data[0].title+'的详情';
			    	setcontent(res.data[0]);
					setpopup(res.data[0]);
				})
			}
			function setpopup(data){
				let list = {
					url:"/api/Address/address_list",
					data:{access_token:acctoken()}
				}
				ajax(list,function(res){
					console.log(res);
					let addstr = "暂无地址，点击设置";
					for(let i = 0; i < res.data.length;i++){
						if(res.data[i].status == 1){
							addid = res.data[i].id;
							addstr = res.data[i].province+' '+res.data[i].city+' '+res.data[i].county+' '+res.data[i].address;
						}
					}
					console.log(addstr);
				let pstr = '<div class="ws_details_close ws_close hide"></div>'+
						'<div class="ws_details_cover"><div class="ws_details_header"><div class="ws_img_wrap ws_100">'+
						'<img src="'+hurl+'/uploads'+data.book_image+'" alt="" />'+
						'</div><div class="ws_main"><div><span class="ws_details_price">'+
						data.price+
						'</span> <i class="mui-icon ws_close mui-icon-close mui-pull-right"></i></div>'+
						'</div></div><div class="ws_details_footer">'+
						'<div class="ws_details_adds" onclick="goaddss()">'+
						'<i class="mui-icon mui-icon-location"></i><span>'+
						addstr+
						'</span><i class="mui-icon mui-icon-arrowright mui-pull-right"></i>'+
						'</div><div class="ws_sum">购买数量'+
						'<div class="mui-numbox ws_sum_btn"  data-numbox-min="1" data-numbox-max="100">'+
						'<button class="mui-btn mui-numbox-btn-minus" type="button">-</button>'+
						'<input class="mui-numbox-input" type="number" id="inputvalue" />'+
						'<button class="mui-btn mui-numbox-btn-plus" type="button">+</button>'+
						'</div></div>'+
						'<div class="mui-input-row"><label>备注</label>'+
						'<input type="text" id="beizhuid" placeholder="请输入备注"></div>'+
						'</div><div class=" ws_play determine hide" onclick="buybook()">确定</div></div>';
				
				g("popdiv").innerHTML = pstr;
				
				mui('.mui-numbox').numbox(); 
				$(".ws_close").click(function(){
					$(".determine").addClass("hide");
					$(".ws_details_close").addClass("hide");
					$(".ws_details_popup").stop(true,true).animate({top:"100%"},400);
				})
				})
			}
			function buybook(){
				
				mui.openWindow({
							    url: 'pay.html', 
							    id:'pay',
							 });
				
				
				
			
						 return;
				var data = {
					url:"/api/Order/orderPreview",
					data:{
						access_token:acctoken(),
						bid:sid
					}
				}
				
				ajax(data,function(res){
					console.log(res);
					let data2 = {
					url:"/api/Order/orderPreview",
					data:{access_token:acctoken(),bid:sid}
				}
				ajax(data2,function(res){
					
					console.log("订单预览："+res);
					
					let bvalue = g("beizhuid").value||"";
					let ivalue = g("inputvalue").value||1;
					let list = {
						url:"/api/Order/orderAdd",
						data:{
							access_token:acctoken(),
							bid:sid,
							address_id:addid,
							preference:bvalue,
							num:ivalue,
						}
					}
					ajax(list,function(res2){
						console.log("订单添加：",res2);
							
						
					})
					
				})
					
					
					
				})
				
				
				 //mui.toast("支付功能未开发！");
				
				
				
				
				
				
			}
			function goaddss(){
				let ist = {ist:1}
				mui.openWindow({
				    url: '../personal/address.html', 
				    id:'address',
				    extras:ist
				 });
				
			}
			function setcontent(data){
				let cstr = '<div class="ws_books_top flex6"><div class="mui-col-xs-4 mui-col-sm-4">'+
							'<div class="ws_books_img">'+
							'<img src="'+hurl+'/uploads'+data.book_image+'" alt="">'+
							'<div class="ws_books_title"></div></div></div><div class="mui-col-xs-8 mui-col-sm-8 flex2"><div>'+
							data.title+
							'</div><div>作者:'+
							data.nickname+
							'</div><div class="wx_books_head font14">共'+
							data.page_total +
							'页    售价'+
							data.price+
							'元</div><div href="member_list.html" class="font14">'+
							data.creatime+
							'</div></div></div>'+
					'<div class="ws_jianjie font14"><div class=" ws_jianjie_title">简介</div>'+
					'<div class="ws_jianjie_content">'+
					data.introduction+
					'</div></div>';
				
				g("contentid").innerHTML = cstr;
				
				
			}
			function gobook4(){
				let list = {bid:sid}
				mui.openWindow({
							url: '../dynamic/book4.html?id='+sid,
							id: 'book4',
							extras:list
				});
			}
			
			function coll(sid){
				let data = {
						url:"/api/Book/book_keep",
						data:{
							access_token : acctoken()||"",
							id:sid
						}
				}
				ajax(data,function(res){
					if(res.code == -1){
						mui.toast(res.message);
					}
					if(res.code == 1){
						console.log(res);
						bookdetails();
					}
				})
			}
			
			function deleteColl(id){
	        		let data = {
						url:"/api/Book/book_keep_delete",
						data:{
							access_token : acctoken()||"",
							id:id
						}
					}
					ajax(data,function(res){
						if(res.code == -1){
							mui.toast(res.message);
						}
						if(res.code == 1){
							console.log(res);
							bookdetails();
							mui.toast("已取消收藏");
							
						}
					})
		    }
			
			
		</script>
	</body>

</html>